/**
 * @author Zou Chris
 */
//
// ---------------------------------------- 全局变量 ------------------------------------------------
//
var selectArticleJqueryMethod_getTagArrayString = function() { alert("selectArticleJqueryMethod_getTagArrayString is not registered"); };
var selectArticleJqueryMethod_getArticleSearchScope = function() { alert("selectArticleJqueryMethod_getArticleSearchScope is not registered"); };
var selectArticleJqueryMethod_getArticleCatagory = function() { alert("selectArticleJqueryMethod_getArticleCatagory is not registered"); };

var selectArticleJqueryMethods_callbackWhenArticleSelected = new Array();

//
//---------------------------------------- 自动执行代码 ------------------------------------------------
//

// 暂无

//
//---------------------------------------- 对外公开的函数 ------------------------------------------------
//
function selectArticleJqueryMethod_registerMethodGetTagArrayString(callback) {
	selectArticleJqueryMethod_getTagArrayString = callback;
}

function selectArticleJqueryMethod_registerMethodGetArticleSearchScope(callback) {
	selectArticleJqueryMethod_getArticleSearchScope = callback;
}

function selectArticleJqueryMethod_registerMethodGetArticleCatagory(callback) {
	selectArticleJqueryMethod_getArticleCatagory = callback;
}

function selectArticleJqueryMethod_registerMethodCallbackWhenArticleSelected(callback) {
	selectArticleJqueryMethods_callbackWhenArticleSelected.push(callback);
}

function selectArticleJqueryMethod_selectArticleImplementaion() {
	var tagArrStr = selectArticleJqueryMethod_getTagArrayString();
	var positionScope = selectArticleJqueryMethod_getArticleSearchScope();
	var articleCatagory = selectArticleJqueryMethod_getArticleCatagory();
	
	// 下面是重构的临时变量，以后需要重新修改
	// 返回四个值 minX, maxX, minY, maxY
	var minX = positionScope[0];
	var maxX = positionScope[1];
	var minY = positionScope[2];
	var maxY = positionScope[3];
	
	// alert("tagArrStr="+tagArrStr+"; positionScope="+minX+":"+minY+"; articleCatagory="+articleCatagory);
	
	$.ajax({
		type: "post",
		url: "ajaxMapForGetArticleRoundPoint.action",
		data: { 
		       x: minX,
		       y: minY,
		       distance: 1
		}, 
		dateType: "json",
		success: function(res) {
			if(res.result == 0) {
				callbackMethodsWhenArticleSelected(res);
			}
			else {
				alert("系统获取信息错误！错误编码为：" + res.result);
			}
		}
	});
}


//
//---------------------------------------- 私有函数 ------------------------------------------------
//

//回调所有需要更新文章的方法
function callbackMethodsWhenArticleSelected(dataSet) {
	if (selectArticleJqueryMethods_callbackWhenArticleSelected.length == 0) {
		alert("selectArticleJqueryMethods_callbackWhenArticleSelected have no method registered");
	}
	else {
		for(var i=0; i<selectArticleJqueryMethods_callbackWhenArticleSelected.length; i++) {
			selectArticleJqueryMethods_callbackWhenArticleSelected[i](dataSet);
		}
		
	}
}